package com.ruoyi.framework.youshuda.cleanup;

import com.mysql.cj.jdbc.AbandonedConnectionCleanupThread;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;

/**
 * 应用关闭时，手动调用 AbandonedConnectionCleanupThread.checkedShutdown() 方法来停止该线程
 */
@Component
@Slf4j
public class MysqlConnectionCleanup {

    @PreDestroy
    public void destroy() {
        try {
            AbandonedConnectionCleanupThread.checkedShutdown();
        } catch (Exception e) {
            log.error("应用关闭前，手动清除MysqlConnection失败，原因："+e.getMessage());
        }
    }
}
